﻿
Imports System.IO
Imports xhtmlctrl

Public Class autoheightIframe
    Inherits iframe

    Public Const functionName As String = "ifreamhgt"

    Public Sub New(ByVal buff As Stream, ByVal inlineScript As inlineScript)
        MyBase.New(buff)
        assert(Not inlineScript Is Nothing, "inlineScript is nothing.")
        scrolling = xhtmlControl_1_1.scrolling_enum.no
        'onload = "this.height=Math.max(this.contentWindow.document.body.scrollHeight" _
        '                            + ", this.contentWindow.document.documentElement.scrollHeight);"
        onload = functionName + "(this)"
        attributes("onresize") = functionName + "(this)"
        inlineScript.addscript(network.http.contentType.textjavascript, "autoheightIframe" _
                               , "function " + functionName + "(me){" + _
                                    "me.height=Math.max(me.contentWindow.document.body.scrollHeight" _
                                                   + ", me.contentWindow.document.documentElement.scrollHeight);" + _
                                              "}")
        '"if(!window.oper){" + _
        '    "if(me.contentDocument && me.contentDocument.body.offsetHeight)" + _
        '        "me.height=me.contentDocument.body.offsetHeight+20;" + _
        '    "else if(me.document && me.document.body.scrollHeight)" + _
        '        "me.height=me.document.body.scrollHeight+10;}" + _
        '"else me.height=me.contentWindow.document.body.scrollHeight;" + _
    End Sub

    Public Sub New(ByVal buff As Stream, ByVal page As xhtmlpage)
        MyClass.New(buff, page.inlineScript())
    End Sub

End Class
